/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.dao.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.ColumnType;
import com.gitee.sunchenbin.mybatis.actable.annotation.Unique;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import org.apache.ibatis.type.EnumTypeHandler;
import org.openislands.oi.config.typehandler.JsonTypeHandler;
import org.openislands.oi.constant.RoleType;
import org.openislands.oi.constant.JobState;
import org.openislands.oi.constant.JobType;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

@TableName(value = "t_job", autoResultMap = true)
public class JobDO extends BaseDO implements Serializable {
    @Unique
    @Column(isNull = false)
    @TableField("f_job_id")
    private String jobId;
    @TableField(value = "f_job_type", typeHandler = EnumTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 20, isNull = false)
    private JobType jobType;
    @TableField("f_user_id")
    private String userId;
    @TableField("f_name")
    private String name;
    @TableField("f_note")
    private String note;
    @TableField("f_conf")
    @Column(type = MySqlTypeConstant.TEXT, isNull = false)
    private String conf;
    @TableField("f_conf_overwrite")
    @Column(type = MySqlTypeConstant.TEXT)
    private String confOverwrite;
    @TableField("f_runtime_conf")
    @Column(type = MySqlTypeConstant.TEXT, isNull = false)
    private String runtimeConf;
    @TableField("f_leader_node")
    @Column(isNull = false)
    private String leaderNode;
    @TableField(value = "f_nodes", typeHandler = JsonTypeHandler.FederatedNodes.class)
    @Column(type = MySqlTypeConstant.TEXT, isNull = false)
    private Map<RoleType, List<String>> nodes;

    @TableField(value = "f_next_state", typeHandler = EnumTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 31, isNull = false)
    private JobState nextState;
    @TableField(value = "f_state", typeHandler = EnumTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 31, isNull = false)
    private JobState state;
    @Column(isNull = false, defaultValue = "0")
    @TableField("f_progress")
    private Integer progress;
    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_start_time")
    private Date startTime;
    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_end_time")
    private Date endTime;
    @TableField("f_elapsed")
    @Column(isNull = false, defaultValue = "0")
    private Integer elapsed;

    public String getJobId() {
        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public JobType getJobType() {
        return jobType;
    }

    public void setJobType(JobType jobType) {
        this.jobType = jobType;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getConf() {
        return conf;
    }

    public void setConf(String conf) {
        this.conf = conf;
    }

    public String getConfOverwrite() {
        return confOverwrite;
    }

    public void setConfOverwrite(String confOverwrite) {
        this.confOverwrite = confOverwrite;
    }

    public String getRuntimeConf() {
        return runtimeConf;
    }

    public void setRuntimeConf(String runtimeConf) {
        this.runtimeConf = runtimeConf;
    }

    public String getLeaderNode() {
        return leaderNode;
    }

    public void setLeaderNode(String leaderNode) {
        this.leaderNode = leaderNode;
    }

    public Map<RoleType, List<String>> getNodes() {
        return nodes;
    }

    public void setNodes(Map<RoleType, List<String>> nodes) {
        this.nodes = nodes;
    }

    public JobState getState() {
        return state;
    }

    public void setState(JobState state) {
        this.state = state;
    }

    public Integer getProgress() {
        return progress;
    }

    public void setProgress(Integer progress) {
        this.progress = progress;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Integer getElapsed() {
        return elapsed;
    }

    public void setElapsed(Integer elapsed) {
        this.elapsed = elapsed;
    }

    public JobState getNextState() {
        return nextState;
    }

    public void setNextState(JobState nextState) {
        this.nextState = nextState;
    }
}